#include <iostream>
#include <string>

std::string const text = "anniversary";
int const len = text.size();

int main()
{
	int T;
	std::cin >> T;
	std::string s;
	while (T--) {
		std::cin >> s;
		bool opt = false;
		for (int i = 1; i <= len - 2; i++) {
			for (int j = 1; i + j <= len - 1; j++) {
				int k = len - i - j;
				std::string s1 = text.substr(0, i);
				std::string s2 = text.substr(i, j);
				std::string s3 = text.substr(i + j, k);
				std::string::size_type l1 = s.find(s1);
				if (l1 == std::string::npos) continue;
				std::string::size_type l2 = s.find(s2, l1+s1.size());
				if (l2 == std::string::npos) continue;
				std::string::size_type l3 = s.find(s3, l2+s2.size());
				if (l3 == std::string::npos) continue;
				opt = true;
				break;
			}
			if (opt) break;
		}
		if (opt)
			std::cout << "YES\n";
		else
			std::cout << "NO\n";
	}
}


